----------------------------------Spell Variables--------------------------------------
SPELL.m_iSpellID = 60 -- Whatever value you want as long as it doesn't override any other spells' IDs.
SPELL.m_iRange = 240
SPELL.m_sName = "Whirlwind"
SPELL.m_sToolTip =	[[You spin in circles, causing 
					 50% weapon damage in all 
					 directions for 5 yards.]]
SPELL.m_sIcon = "devin/blackbetty/spells/warrior/whirlwind.png"
SPELL.m_iCoolDown = 3
SPELL.m_iManaCost = 15
SPELL.m_bRequiresTarget = false
SPELL.m_iSpellType = SPELLTYPE_MAA

---------------------------------------------------------------------------------------

local range = 100
local weapondamage = 10

function SPELL:Cast( pl, target )
	print("Casted "..self.m_sName.."!")
		pl.InSpellAnimation = true
		if(pl:IsPlayer())then
			pl:DoAnimationEvent(ACT_DI_ALYX_ZOMBIE_MELEE)
		else
			pl:RestartGesture(ACT_DI_ALYX_ZOMBIE_MELEE)
		end
			local target = nil
		local weapon = nil
		if(pl:IsPlayer())then
			weapon = pl:GetWeapon("weapon_all")
			target = pl:GetNetworkedEntity("Target")
		else
			target = pl.Target
		end
		pl.DoingCast = true
		pl.CastWhileMoving = true
		pl:EmitSound("devin/blackbetty/player/male/swing_common"..math.random(1,3)..".wav", 100, 100)
		pl:EmitSound("devin/blackbetty/weapons/whirlwind/whirlwind.wav", 100, 100)
		local whirlRadius = ents.FindInSphere(pl:GetPos(), 240)
		ParticleEffectAttach( "whirlwind", PATTACH_POINT_FOLLOW, pl, pl:LookupAttachment("anim_attachment_RH"))
		pl.DoingCast = true
		pl.CastWhileMoving = true
		timer.Simple(0.2, function()
			pl.DoingCast = false
			pl:StopParticles()
		end)
		net.Start( "SendPlayerCast" )
		local SendTable = {0.2, self.m_sName, Color(155, 155, 155, 255)}
		net.WriteTable(SendTable)
		net.Send(pl)
		timer.Simple(0.05, function()
			for i, s in pairs(whirlRadius)do
				if(s and s:EntIndex() != pl:EntIndex() and s:IsPlayer() or s:IsNPC() or s:GetClass() == "npc_rpgdm")then
					local dmginfo = DamageInfo()
						dmginfo:SetDamage(math.Round(math.random(weapon.MinWeaponDamage*0.75, weapon.MaxWeaponDamage*0.75))) --50 damage
						dmginfo:SetDamageType( DMG_SLASH ) --Bullet damage
						dmginfo:SetAttacker( pl ) --First player found gets credit
						dmginfo:SetDamageForce( Vector( 0, 0, 1000 ) ) --Launch upwards
					s:EmitSound("devin/blackbetty/weapons/Warrior_ShockWave_Area.wav", 150, 100+math.random(30,60))
					s:TakeDamageInfo( dmginfo )
					ParticleEffect( "pummel_hit", s:GetPos() + Vector(0, 0, 46) + (s:GetAngles():Forward()*6), Angle(0,0,0), pl )
					ParticleEffect( "player_blood", s:GetPos() + Vector(0, 0, 46) + (s:GetAngles():Forward()*6), Angle(0,0,0), pl )
					if SERVER then
						s:SetVelocity(((pl:GetPos()- Vector(0, 0, 40)) - s:GetPos())*-3)
					end	
				end
			end
		end)
		timer.Simple(0.8, function()
			pl.InSpellAnimation = false
			pl:SetNWBool("Casting", false)
			pl:SetNWBool("Casted", false)
		end)
	end





